const man = {
  name: 'aa',
  city: 'nc'
};

// const proxy = new Proxy(man,{
//   get(target,property,receiver){
//     console.log(target, property, receiver);
//     return target[property]
//   }
// })

// console.log(proxy.name)

function enhancedArray(arr) {
  return new Proxy(arr, {
    get(target, property, receiver) {
      const range = getRange(property);
      
      const indices = range ? range : getIndices(property);

      const values = indices.map(function (index) {
        const key = index < 0 ? String(target.length + index) : index;
        return Reflect.get(target, key, receiver);
      });
      
      return values.length === 1 ? values[0] : values;
    }
  });
}

function getRange(str) {
  var [start, end] = str.split(':').map(Number);

  if (typeof end === 'undefined') return false;

  let range = [];
  for (let i = start; i <= end; i++) {
    range = range.concat(i);
  }

  return range;
}

function getIndices(str) {
  return str.split(',').map(Number);
}

const arr = enhancedArray([1, 2, 3, 4, 5]);


// arr[-1]
console.log(arr[[2, 4]]);
// console.log(arr["2:4"]);
